<template>
  <div class="app-container">
    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="780px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="98px"
      >
        <el-col :span="24">
          <el-form-item label="生产日期">
            <el-date-picker
              v-model="daterangeSclRq"
              size="small"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :picker-options="pickerOptions"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>

          <el-col :span="12">
            <el-form-item label="制造单号" prop="sclZzdh">
              <el-input
                v-model="queryParams.sclZzdh"
                placeholder="请输入制造单号"
                clearable
                size="small"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="物料代码" prop="sclWldm">
              <el-input
                v-model="queryParams.sclWldm"
                placeholder="请输入物料代码"
                clearable
                size="small"
              />
            </el-form-item>
          </el-col>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          @click="handleSearch"
          size="small"
          >查询</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="
            handleExport('#ComparativeAnalysis', '良品入库对比分析-明细数据')
          "
          size="small"
        >
          明细数据
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          @click="
            handleExport(
              '#ComparativeAnalysisStatistics',
              '良品入库对比分析-统计信息'
            )
          "
          size="small"
        >
          统计信息
        </el-button>
      </el-col>
    </el-row>
    <el-tabs v-model="activeTab">
      <el-tab-pane label="明细数据" name="first">
        <el-table
          border
          stripe
          id="ComparativeAnalysis"
          :height="tableH"
          @scrollBottom="load"
          :data="SclDetList"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="生产日期"
            align="center"
            width="135"
            prop="sclScrq"
          >
            <template #default="scope">
              <span>{{ parseTime(scope.row.sclScrq, "{y}-{m}-{d}") }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="制造单号"
            align="center"
            width="135"
            prop="sclZzdh"
          />
          <el-table-column
            label="物料代码"
            align="center"
            prop="sclWldm"
            width="135"
          />
          <el-table-column label="品名规格" prop="sclPmgg" width="280" />
          <el-table-column label="良品数量" prop="sclLpsl" width="280" />
          <el-table-column label="申请入库" prop="sclSqsl" width="280" />
          <el-table-column label="允收数量" prop="sclYssl" width="280" />
          <el-table-column label="拒收数量" prop="sclJssl" width="280" />
          <el-table-column label="入库数量" prop="sclRksl" width="280" />
          <el-table-column label="入库差异" prop="sclRkcy" width="280" />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="统计信息" name="second">
        <el-table
          border
          stripe
          id="ComparativeAnalysisStatistics"
          :height="tableH"
          @scrollBottom="load2"
          :data="rwdDateTotal"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column
            label="#"
            type="index"
            width="55"
            align="center"
            fixed="left"
          />
          <el-table-column
            label="物料代码"
            align="center"
            prop="sclWldm"
            width="135"
          />
          <el-table-column label="品名规格" prop="sclPmgg" width="280" />
          <el-table-column label="良品数量" prop="sclLpsl" width="280" />
          <el-table-column label="申请入库" prop="sclSqsl" width="280" />
          <el-table-column label="允收数量" prop="sclYssl" width="280" />
          <el-table-column label="拒收数量" prop="sclJssl" width="280" />
          <el-table-column label="入库数量" prop="sclRksl" width="280" />
          <el-table-column label="入库差异" prop="sclRkcy" width="280" />
        </el-table>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import { exportTable } from "@/utils/ruoyi";
import { handleList } from "@/api/production/ComparativeAnalysis";

export default {
  name: "ComparativeAnalysis",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      serachChildren: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      tableH: document.body.clientHeight - 300,
      single: true,
      activeTab: "first",
      // 非多个禁用
      multiple: true,
      SclDetList: [],
      rwdDateTotal: [],
      rwdCsTotal: [],
      rwdCkTotal: [],
      rwdWldmList: [],
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      openChildren: false,
      // 总条数
      total: 0,
      total2: 0,

      // 弹出层标题
      title: "",
      addDate: true,
      // 是否显示弹出层
      open: false,
      // 建立日期时间范围
      daterangeSclRq: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],
      rkmxList: [],
      rktjList: [],
      qgmxList: [],
      rowData: null,
      qgdDetCountList: [],
      serachAddList: [],
      unitFlagOptions: [],
      //所有客户
      allCustomerOptions: [],
      selectioned: [],
      type1: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 25,
        sclZzdh: null,
        sclWldm: null,
      },

      // 表单参数
      form: {},
      // 表单校验
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询来料进货入库开单列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeSclRq && "" != this.daterangeSclRq) {
        this.queryParams.params["beginSclScrq"] = this.moment(
          this.daterangeSclRq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endSclScrq"] = this.moment(
          this.daterangeSclRq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      handleList(this.queryParams).then((response) => {
        //明细
        this.SclDetList = this.SclDetList.concat(response.data.list1.rows);
        this.total = response.data.list1.total;

        //统计
        this.rwdDateTotal = this.SclDetList.concat(response.data.list2.rows);
        this.total2 = response.data.list2.total;
      });
    },
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 25;
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    load2() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total2 / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 25;
        this.queryParams.pageNum++;
        this.getList();
      }
      return 0;
    },
    handleSearch() {
      this.openSearch = true;
      this.title = "查询";
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.openChildren = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
      this.openSearch = false;
    },
    // 表单重置
    reset() {
      this.form = {
        sclZzdh: null,
        sclWldm: null,
      };
      this.resetForm("form");
    },
    //导出Excel
    handleExport(a, b) {
      exportTable(a, b);
    },
  },
};
</script>

<style scoped></style>
